-
Notifications
You must be signed in to change notification settings - Fork 0
Implement proper Codegen SDK response handling #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
# Motivation The **Codegen on OSS** package provides a pipeline that: - **Collects repository URLs** from different sources (e.g., CSV files or GitHub searches). - **Parses repositories** using the codegen tool. - **Profiles performance** and logs metrics for each parsing run. - **Logs errors** to help pinpoint parsing failures or performance bottlenecks. <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> see [codegen-on-oss/README.md](https://github.com/codegen-sh/codegen-sdk/blob/acfe3dc07b65670af33b977fa1e7bc8627fd714e/codegen-on-oss/README.md) # Testing <!-- How was the change tested? --> `uv run modal run modal_run.py` No unit tests yet 😿 # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [x] I have updated the documentation or added new documentation as needed
Original commit by Tawsif Kamal: Revert "Revert "Adding Schema for Tool Outputs"" (codegen-sh#894) Reverts codegen-sh#892 --------- Co-authored-by: Rushil Patel <[email protected]> Co-authored-by: rushilpatel0 <[email protected]>
Original commit by Ellen Agarwal: fix: Workaround for relace not adding newlines (codegen-sh#907)
…-enhanced-visualization-features
…oyment-scripts
- Add proper task response types matching Codegen SDK - Fix task result handling in streaming mode - Improve task status updates and error handling - Add better message content updates
Reviewer's GuideThis PR introduces a new CodegenAPI service that implements both synchronous and streaming task execution conforming to the Codegen SDK types, adds strict TypeScript interfaces for backend responses and internal models, enhances error handling (including 500-status fallbacks and fetch error catches), applies throttled status updates with local storage persistence, and wires these mechanics into the React App to update chat messages via custom events. Sequence Diagram for Streaming Task Execution and UI UpdatesequenceDiagram
actor User
participant App_tsx as Frontend App
participant CodegenAPI
participant Backend_API as Backend API
participant LocalStorage
User->>App_tsx: Sends a message (prompt)
App_tsx->>CodegenAPI: runAgentStreaming(prompt)
CodegenAPI->>CodegenAPI: generateTaskId()
CodegenAPI->>LocalStorage: storeTask(initial pending task)
CodegenAPI->>Backend_API: POST /run-task (stream=true, prompt)
Backend_API-->>CodegenAPI: Stream Response (chunks)
loop For each data chunk
CodegenAPI->>CodegenAPI: Parses chunk
CodegenAPI->>LocalStorage: storeTask(updated task with result/status)
CodegenAPI->>App_tsx: Dispatches 'taskUpdate' event (throttled)
App_tsx->>App_tsx: Updates UI (ChatArea)
end
alt Stream ends with [DONE]
CodegenAPI->>LocalStorage: storeTask(task status: completed)
CodegenAPI->>App_tsx: Dispatches 'taskUpdate' event
App_tsx->>App_tsx: Updates UI
else Stream ends or error, final status check
CodegenAPI->>Backend_API: GET /task/{taskId}/status (to confirm final state)
Backend_API-->>CodegenAPI: Final task status
CodegenAPI->>LocalStorage: storeTask(final task)
CodegenAPI->>App_tsx: Dispatches 'taskUpdate' event
App_tsx->>App_tsx: Updates UI
end
Entity Relationship Diagram for New Frontend Data ModelserDiagram
Thread {
string id PK
string name
datetime createdAt
}
Message {
string id PK
string content
string type "user, assistant, error"
string taskId FK "nullable"
string status "TaskStatus, nullable"
datetime createdAt
}
Task {
string id PK
string prompt
string status "TaskStatus"
string result "nullable"
string error "nullable"
datetime createdAt
datetime updatedAt
}
CodegenConfig {
string orgId
string token
boolean isConnected
}
Thread ||--|{ Message : has
Message }o--o| Task : references
Class Diagram for CodegenAPI and Related TypesclassDiagram
direction LR
class CodegenAPI {
-orgId: string
-token: string
-baseUrl: string
+configure(orgId: string, token: string)
+isConfigured(): boolean
+testConnection(): Promise<boolean>
+runAgent(prompt: string, streaming: boolean): Promise<Task>
-runAgentSync(prompt: string): Promise<Task>
-runAgentStreaming(prompt: string): Promise<Task>
-handleStreamingResponse(response: Response, taskId: string)
+getTaskStatus(taskId: string): Promise<Task | null>
-mapStatus(apiStatus: string): TaskStatus
-generateTaskId(): string
-getStoredTask(taskId: string): Task | null
+storeTask(task: Task)
+cleanup()
}
class Task {
<<Interface>>
id: string
prompt: string
status: TaskStatus
result?: string
error?: string
createdAt: Date
updatedAt: Date
}
class Message {
<<Interface>>
id: string
content: string
type: 'user' | 'assistant' | 'error'
taskId?: string
status?: TaskStatus
createdAt: Date
}
class Thread {
<<Interface>>
id: string
name: string
messages: Message[]
createdAt: Date
}
class CodegenConfig {
<<Interface>>
orgId: string
token: string
isConnected: boolean
}
class BackendTaskResponse {
<<Interface>>
id: string
organization_id: string
status: string
created_at: string
result?: string
error?: string
web_url?: string
}
class BackendTaskStatusResponse {
<<Interface>>
id: string
organization_id: string
status: string
created_at: string
result?: string
error?: string
web_url?: string
}
class App_tsx {
<<React Component>>
+handleSendMessage(content: string)
+handleTaskUpdate(event: CustomEvent)
}
App_tsx ..> CodegenAPI : uses
CodegenAPI ..> Task : creates/updates
CodegenAPI ..> BackendTaskResponse : processes
CodegenAPI ..> BackendTaskStatusResponse : processes
App_tsx ..> Message : creates/updates
App_tsx ..> Thread : manages
Thread *-- "many" Message : contains
Message ..> Task : references
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Join our Discord community for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This PR implements proper task response handling based on the Codegen SDK:
Task Response Types:
AgentRunResponseTask Result Handling:
Status Updates:
Error Handling:
These changes ensure:
To test:
Send a message and verify:
Test error scenarios:
💻 View my work • About Codegen
Summary by Sourcery
Implement a new CodegenAPI client for configuring, running, and tracking tasks with both streaming and synchronous modes, integrate real-time task updates and error handling into the UI, and persist task state for reliability
New Features:
Bug Fixes:
Enhancements: